package com.jy.adscm.operation.hscrb.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.operation.hscrb.bean.JxParsingdetail;
import com.jy.adscm.operation.hscrb.mapper.mysql.JxParsingdetailMapper;
import com.jy.adscm.operation.hscrb.service.JxParsingdetailService;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2018-12-14
 */
@Service
public class JxParsingdetailServiceImpl extends ServiceImpl<JxParsingdetailMapper, JxParsingdetail> implements JxParsingdetailService {
   @Autowired
    JyUserMapper jyUserMapper;
    @Override
    public Boolean updateJxParsingdetail(JxParsingdetail jxParsingdetail) {
        boolean result = super.updateById(jxParsingdetail);
        return result;
    }

    @Override
    public List<JxParsingdetail> selectByTid(String tid) {
        Wrapper<JxParsingdetail> wrapper =new EntityWrapper<>();
        wrapper.eq("TID",tid);
        List<JxParsingdetail> jxParsingdetails = super.selectList(wrapper);
        for (JxParsingdetail jxParsingdetail : jxParsingdetails) {
              if (AdscmBaseUtils.getInstance().isNotEmpty(jxParsingdetail.getBegintime(),null)){
                  JyUser jyUser = jyUserMapper.selectById(jxParsingdetail.getBegintime());
                  jxParsingdetail.setBegintimeName(jyUser.getName());
              }
              if (AdscmBaseUtils.getInstance().isNotEmpty(jxParsingdetail.getCustomer(),null)){
                  JyUser jyUser = jyUserMapper.selectById(jxParsingdetail.getCustomer());
                  jxParsingdetail.setCustomerName(jyUser.getName());
              }
              if (AdscmBaseUtils.getInstance().isNotEmpty(jxParsingdetail.getNeeder(),null)){
                  JyUser jyUser = jyUserMapper.selectById(jxParsingdetail.getNeeder());
                  jxParsingdetail.setNeederName(jyUser.getName());
              }
              if (AdscmBaseUtils.getInstance().isNotEmpty(jxParsingdetail.getNeednums(),null)){
                  JyUser jyUser = jyUserMapper.selectById(jxParsingdetail.getNeednums());
                  jxParsingdetail.setNeednumsName(jyUser.getName());
              }
        }
        return jxParsingdetails;
    }

    @Override
    public List<JyUser> selectUser() {
         Wrapper<JyUser> wrapper =new EntityWrapper<>();
         wrapper.setSqlSelect("id","name");
        List<JyUser> jyUsers = jyUserMapper.selectList(wrapper);
        return jyUsers;
    }
}
